<template>
  <div>
    <div id="echarts1" style="height: 700px;width: 600px;display: inline-block;margin-right: 20px"></div>
    <div id="echarts2" style="height: 700px;width: 600px;display: inline-block"></div>
  </div>
</template>

<script>
import echarts from 'echarts'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/bar'
import 'echarts/lib/chart/pie'
import 'echarts/lib/chart/tree'

export default {
  name: 'Echarts',
  mounted () {
    this.lineEcharts('echarts1')
    this.timelineEcharts('echarts2')
  },
  methods: {
    lineEcharts (id) {
      this.chart = echarts.init(document.getElementById(id), 'dark')
      let option = {
        title: {
          text: '折线图堆叠',
          link: 'https://www.baidu.com',
          textStyle: {color: '#00ff0e'}
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'line'
          }
        },
        legend: {
          right: 20,
          data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {},
            dataView: {}
          }
        },
        xAxis: {
          type: 'category',
          data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        },
        yAxis: {
          name: '数量',
          type: 'value'
        },
        series: [
          {
            name: '邮件营销',
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '联盟广告',
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: '视频广告',
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: '直接访问',
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: '搜索引擎',
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      }
      this.chart.setOption(option)
    },
    timelineEcharts (id) {
      this.chart = echarts.init(document.getElementById(id), 'dark')
      let base = {
        timeline: {
          autoPlay: true,
          playInterval: 3000,
          data: ['2002-01-01', '2003-01-01', '2004-01-01']
        },
        title: {
          subtext: '数据来自国家统计局'
        },
        xAxis: {
          boundaryGap: true,
          data: ['山东', '四川', '广州', '台湾', '巴黎', '美国', '意大利']
        },
        yAxis: {
          type: 'value'
        },
        legend: {
          data: ['邮件营销', '联盟广告', '直接访问']
        },
        series: [
          {type: 'line'},
          {type: 'bar'}]
      }
      let option = [
        {
          title: {
            text: '2002年统计值'
          },
          series: [
            {
              data: [1, 2, 3, 5, 6, 1, 5]},
            {
              data: [1, 2, 3, 5, 6, 1, 5]}
          ]
        },
        { // 这是'2003-01-01' 对应的 option
          title: {
            text: '2003年统计值'
          },
          series: [
            {
              data: [3, 5, 1, 21, 6, 1, 5]},
            {
              data: [3, 5, 1, 21, 6, 1, 5]}
          ]
        },
        { // 这是'2004-01-01' 对应的 option
          title: {
            text: '2004年统计值'
          },
          series: [
            {
              data: [1, 2, 34, 5, 6, 1, 5]},
            {
              data: [1, 2, 34, 5, 6, 1, 5]}
          ]
        }
      ]
      this.chart.setOption({
        baseOption: base,
        options: option
      })
    }
  }
}
</script>

<style scoped>

</style>
